/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.openbookformat.obffinder;

import java.io.File;
import org.openbookformat.obffinder.filters.FilterSelectionDialog;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.openide.loaders.DataObjectNotFoundException;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.util.ImageUtilities;
import org.netbeans.api.settings.ConvertAsProperties;
import org.netbeans.spi.project.ui.support.FileSensitiveActions;
import org.openbookformat.chaptersviewer.OBFChaptersViewerTopComponent;
import org.openbookformat.obffinder.filters.Filter;
import org.openbookformat.obffinder.filters.FiltersManager;
import org.openbookformat.obffinder.filters.FindReplaceFilter;
import org.openbookformat.obffinder.filters.FixedFilter;
import org.openbookformat.obffinder.filters.ReplaceFilter;
import org.openbookformat.obffinder.filters.SaveFilterDialog;
import org.openbookformat.project.OBFProjectFactory;
import org.openbookformat.project.ProjectUtil;
import org.openide.cookies.EditorCookie;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataObject;
import org.openide.nodes.Node;
import org.openide.util.lookup.Lookups;
import org.openide.windows.WindowManager;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(dtd = "-//org.openbookformat.obffinder//OBFFindnReplace//EN",
autostore = false)
public final class OBFFindnReplaceTopComponent extends TopComponent 
        implements Observer{

    private static OBFFindnReplaceTopComponent instance;
    /** path to the icon used by the component and its open action */
    static final String ICON_PATH = "org/openbookformat/obffinder/folder_explore.png";
    private static final String PREFERRED_ID = "OBFFindnReplaceTopComponent";

    public OBFFindnReplaceTopComponent() {
        initComponents();
        setName(NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "CTL_OBFFindnReplaceTopComponent"));
        setToolTipText(NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "HINT_OBFFindnReplaceTopComponent"));
        setIcon(ImageUtilities.loadImage(ICON_PATH, true));
        observable = new MyObservable();
        associateLookup(Lookups.fixed(observable));
        FiltersManager.getInstance();

        filter = new FixedFilter(
            "Fixed Filter",
            jFind.getText(),
            jReplace.getText(),
            jUseRegExp.getState(),
            jIgnoreCase.getState(),
            jUseVar.getState(),
            jApplyToAll.getState(),
            jIgnoreNewLine.getState(),
            "");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jFind = new javax.swing.JTextArea();
        jScrollPane2 = new javax.swing.JScrollPane();
        jReplace = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jUseRegExp = new java.awt.Checkbox();
        jIgnoreCase = new java.awt.Checkbox();
        jUseVar = new java.awt.Checkbox();
        jApplyToAll = new java.awt.Checkbox();
        jIgnoreNewLine = new java.awt.Checkbox();
        jSearch = new javax.swing.JButton();
        jFilter = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jName = new javax.swing.JTextField();
        jSaveFilter = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jApplyToHeading = new java.awt.Checkbox();

        setOpaque(true);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel1.setForeground(java.awt.Color.blue);
        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jLabel1.text")); // NOI18N

        jFind.setColumns(20);
        jFind.setRows(5);
        jScrollPane1.setViewportView(jFind);

        jReplace.setColumns(20);
        jReplace.setRows(5);
        jScrollPane2.setViewportView(jReplace);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setForeground(java.awt.Color.blue);
        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jLabel2.text")); // NOI18N

        jUseRegExp.setLabel(org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jUseRegExp.label")); // NOI18N

        jIgnoreCase.setLabel(org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jIgnoreCase.label")); // NOI18N

        jUseVar.setLabel(org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jUseVar.label")); // NOI18N

        jApplyToAll.setLabel(org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jApplyToAll.label")); // NOI18N

        jIgnoreNewLine.setLabel(org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jIgnoreNewLine.label")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jSearch, org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jSearch.text")); // NOI18N
        jSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jSearchActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jFilter, org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jFilter.text")); // NOI18N
        jFilter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jFilterActionPerformed(evt);
            }
        });

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel4.setForeground(java.awt.Color.blue);
        org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jLabel4.text")); // NOI18N

        jName.setText(org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jName.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jSaveFilter, org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jSaveFilter.text")); // NOI18N
        jSaveFilter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jSaveFilterActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jButton1, org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jButton1.text")); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jApplyToHeading.setLabel(org.openide.util.NbBundle.getMessage(OBFFindnReplaceTopComponent.class, "OBFFindnReplaceTopComponent.jApplyToHeading.label")); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2)
                            .addComponent(jLabel4))
                        .addGap(25, 25, 25)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addComponent(jName, javax.swing.GroupLayout.DEFAULT_SIZE, 218, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton1))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jApplyToAll, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jUseVar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jIgnoreCase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jUseRegExp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jFilter)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jSaveFilter)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 58, Short.MAX_VALUE)
                                .addComponent(jSearch))
                            .addComponent(jIgnoreNewLine, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jApplyToHeading, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jUseRegExp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jIgnoreNewLine, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jIgnoreCase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jApplyToHeading, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jUseVar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jApplyToAll, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jFilter)
                    .addComponent(jSearch)
                    .addComponent(jSaveFilter))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    
    private void jSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jSearchActionPerformed
        //Get selected chapters, do a search on each; fire findResults result changed.a
        Node[] sNodes = null;
        if(jApplyToAll.getState()) {
            sNodes = OBFChaptersViewerTopComponent.getDefault().
                getExplorerManager().getRootContext().getChildren().getNodes();
        } else {
            sNodes = OBFChaptersViewerTopComponent.getDefault().
                getExplorerManager().getSelectedNodes();
        }
        for(int i =0; i < sNodes.length; i++)
            System.out.println(sNodes[i]);        
        findResults.clear();
        
        boolean includeHeading = jApplyToHeading.getState();
        DataObject headingDO = null;
        try {
            if(ProjectUtil.getInstance().getProject() == null) { 
                includeHeading = false;
            } else {
                headingDO = DataObject.find(ProjectUtil.getInstance().getProject().
                getProjectDirectory().getFileObject(OBFProjectFactory.HEADING_FILE));
            }
        } catch (DataObjectNotFoundException ex) {
            Exceptions.printStackTrace(ex);
        }
        
        if(filter instanceof FindReplaceFilter) {
            ArrayList<DataObject> dObj = new ArrayList<DataObject>();            
            for(int i = 0; i < sNodes.length; i++) {
                dObj.add(sNodes[i].getLookup().lookup(DataObject.class));                
            }
            if(includeHeading) {
               dObj.add(headingDO); 
            }
            ((FindReplaceFilter) filter).setChapters(dObj);
            findResults = ((FindReplaceFilter) filter).find();            
        } else {
            //Create FileUtil object
            FindUtil fu = new  FindUtil(jFind.getText(), jReplace.getText());
            fu.setRegExp(jUseRegExp.getState());
            fu.setIgnoreCase(jIgnoreCase.getState());
            fu.setUseVariables(jUseVar.getState());
            fu.setUseIgonreNewLine(jIgnoreNewLine.getState());

            if(filter instanceof ReplaceFilter) {
                fu.setFilter(filter);
            }
                    
            DataObject dObj = null;
            for(int i = 0; i < sNodes.length; i++) {
                dObj = sNodes[i].getLookup().lookup(DataObject.class);
                findResults.put(dObj, fu.find(dObj.getCookie(EditorCookie.class)));
            }
            if(includeHeading) {
               findResults.put(headingDO, fu.find(headingDO.getCookie(EditorCookie.class)));
            }
        }
        
        observable.resultChanged();
    }//GEN-LAST:event_jSearchActionPerformed


    private void jFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFilterActionPerformed
        FilterSelectionDialog dialog = new FilterSelectionDialog(null, true);
        dialog.addObserver(this);
        dialog.setVisible(true);
        dialog.deleteObserver(this);
        if(dialog.isOkSelected()) {
            filter = dialog.getSelectedFilter();
        } else {
            applyFilter(filter);
        }
    }//GEN-LAST:event_jFilterActionPerformed

    private void jSaveFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jSaveFilterActionPerformed
        if (filter instanceof FixedFilter) {
            updateFilterData(filter);
            SaveFilterDialog dialog = new SaveFilterDialog(null, true);
            dialog.setFilterName(jName.getName());
            dialog.setFilterDescription(filter.getDescription());
            dialog.setVisible(true);

            if (dialog.isOkSelected()) {
                if (FiltersManager.getInstance().exist(dialog.getFilterName())) {
                    int ans = JOptionPane.showConfirmDialog(null,
                            "Filter already exists. continue?");
                    if (ans == JOptionPane.NO_OPTION) {
                        return;
                    }
                }
                
                filter = new FixedFilter(
                        dialog.getFilterName(),
                        jFind.getText(),
                        jReplace.getText(),
                        jUseRegExp.getState(),
                        jIgnoreCase.getState(),
                        jUseVar.getState(),
                        jApplyToAll.getState(),
                        jIgnoreNewLine.getState(),
                        dialog.getFilterDescription());
                applyFilter(filter);
                FiltersManager.getInstance().saveFilter(filter);
            }
        }              
    }//GEN-LAST:event_jSaveFilterActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        FixedFilter aFilter = new FixedFilter(jName.getText());
        updateFilterData(aFilter);
        filter = aFilter;
    }//GEN-LAST:event_jButton1ActionPerformed

    private void updateFilterData(Filter filter) {
        filter.setFindText(jFind.getText());
        filter.setReplaceText(jReplace.getText());
        filter.setRegExp(jUseRegExp.getState());
        filter.setIgnoreCase(jIgnoreCase.getState());
        filter.setUseVariables(jUseVar.getState());
        filter.setApplyToAll(jApplyToAll.getState());
        filter.setUseIgonreNewLine(jIgnoreNewLine.getState());
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private java.awt.Checkbox jApplyToAll;
    private java.awt.Checkbox jApplyToHeading;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jFilter;
    private javax.swing.JTextArea jFind;
    private java.awt.Checkbox jIgnoreCase;
    private java.awt.Checkbox jIgnoreNewLine;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JTextField jName;
    private javax.swing.JTextArea jReplace;
    private javax.swing.JButton jSaveFilter;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jSearch;
    private java.awt.Checkbox jUseRegExp;
    private java.awt.Checkbox jUseVar;
    // End of variables declaration//GEN-END:variables
    private Filter filter;

    /**
     * Gets default instance. Do not use directly: reserved for *.settings files only,
     * i.e. deserialization routines; otherwise you could get a non-deserialized instance.
     * To obtain the singleton instance, use {@link #findInstance}.
     */
    public static synchronized OBFFindnReplaceTopComponent getDefault() {
        if (instance == null) {
            instance = new OBFFindnReplaceTopComponent();
        }
        return instance;
    }

    /**
     * Obtain the OBFFindnReplaceTopComponent instance. Never call {@link #getDefault} directly!
     */
    public static synchronized OBFFindnReplaceTopComponent findInstance() {
        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
        if (win == null) {
            Logger.getLogger(OBFFindnReplaceTopComponent.class.getName()).warning(
                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
            return getDefault();
        }
        if (win instanceof OBFFindnReplaceTopComponent) {
            return (OBFFindnReplaceTopComponent) win;
        }
        Logger.getLogger(OBFFindnReplaceTopComponent.class.getName()).warning(
                "There seem to be multiple components with the '" + PREFERRED_ID
                + "' ID. That is a potential source of errors and unexpected behavior.");
        return getDefault();
    }

    @Override
    public int getPersistenceType() {
        return TopComponent.PERSISTENCE_ALWAYS;
    }

    @Override
    public void componentOpened() {
        // TODO add custom code on component opening
    }

    @Override
    public void componentClosed() {
        // TODO add custom code on component closing
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    Object readProperties(java.util.Properties p) {
        if (instance == null) {
            instance = this;
        }
        instance.readPropertiesImpl(p);
        return instance;
    }

    private void readPropertiesImpl(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }

    @Override
    protected String preferredID() {
        return PREFERRED_ID;
    }

    Map<DataObject, ArrayList<FindResult>> findResults =
            new HashMap<DataObject, ArrayList<FindResult>>();
    MyObservable observable;

    @Override
    public void update(Observable o, Object arg) {
        System.out.println("Filter Changed:" + ((Filter) arg).getName());
        applyFilter((Filter) arg);
    }

    private void applyFilter(Filter filter) {
        jName.setText(filter.getName());
        jFind.setText(filter.getFindText());
        jReplace.setText(filter.getReplaceText());
        jUseRegExp.setState(filter.isRegExp());
        jIgnoreCase.setState(filter.isIgnoreCase());
        jUseVar.setState(filter.isUseVariables());
        jApplyToAll.setState(filter.isApplyToAll());
        jIgnoreNewLine.setState(filter.isIgnoreCase());
    }

    class MyObservable extends Observable {

        void resultChanged() {
            System.out.println("Find Result Changed! - " + findResults.size());
            super.setChanged();
            super.notifyObservers(findResults);
        }
    }

}
